package com.net.xpay.common.manager.impl.openapi;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.openapi.OpenAppMapper;
import com.net.xpay.common.domain.openapi.OpenApp;
import com.net.xpay.common.manager.openapi.OpenAppManager;
import com.net.common.manager.AbstractManager;
import com.net.xpay.core.model.OpenAppSearchModel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class OpenAppManagerImpl extends AbstractManager<OpenApp> implements OpenAppManager {

    @Autowired
    private OpenAppMapper mapper;


    @Override
    protected BasicMapper<Long, OpenApp> getMapper() {
        return mapper;
    }

    @Override
    public List<OpenApp> search(OpenAppSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(OpenAppSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public OpenApp getByUserId(Long userId) {
        Preconditions.checkArgument(userId != null);
        OpenApp condition = new OpenApp();
        condition.setUserId(userId);
        return getByCondition(condition);
    }
}
